package com.invite.me.beans.presenter;

import android.util.Log;


import com.google.gson.Gson;
import com.invite.me.api.UrlConstants;
import com.invite.me.beans.res.YaoQingmaShouBean;
import com.invite.me.ui.cehualan.InvitationCodeActivity;
import com.invite.me.util.SspPrefUtils;
import com.invite.me.wlqq.Constants;
import com.invite.me.wlqq.Contract;
import com.invite.me.wlqq.RxJavaDataImpl;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import io.reactivex.Observer;
import io.reactivex.disposables.Disposable;
import okhttp3.ResponseBody;

public class InvitationCodePresenter implements Contract.BasePresenter{

    InvitationCodeActivity splashActivity;

    public InvitationCodePresenter(InvitationCodeActivity signInActivity) {
        this.splashActivity = signInActivity;
        splashActivity.setPresenter(this);
    }

    @Override
    public void start() {

    }

    //获取二维码
    public void yanzhengma(){

        Map<String, Object> headrMap = new HashMap<>();
        headrMap.put("Content-Type", "application/json");
         headrMap.put("userId", SspPrefUtils.getString(Constants.SSPTOKEN, ""));
        //   headrMap.put("userId", "fd91f489ca8fadc3fb12636df5e2c84d");
//        InformationxxFaBean logeInDataBean = new InformationxxFaBean();
//        Gson gson = new Gson();
//        String phoneNumber = gson.toJson(logeInDataBean);
//        RequestBody requestBody = RxJavaDataImpl.getRequestBody(phoneNumber);
        RxJavaDataImpl.postDataa(UrlConstants.TIGONGERWEIMA, headrMap, new Observer() {
            @Override
            public void onSubscribe(Disposable d) {

            }

            @Override
            public void onNext(Object value) {
                if (value instanceof ResponseBody) {
                    try {
                        ResponseBody responseBody = (ResponseBody) value;
                        String str = responseBody.string();
                        Gson gson = new Gson();
                        YaoQingmaShouBean gankInfo = gson.fromJson(str, YaoQingmaShouBean.class);

                        splashActivity.onDataSucess(gankInfo);


                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
            }

            @Override
            public void onError(Throwable e) {
                Log.e("onerror", e+"" );
                splashActivity.onDataFaile(e);
            }

            @Override
            public void onComplete() {
                splashActivity.onComplete();
            }
        });
    }
}
